﻿using Hotel.BLL;
using Hotel.DAL;
using Hotel.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HouseTypeController : ControllerBase
    {
        public HouseTypeController(HouseTypeBLL houseTypeBLL) 
        {
            HouseTypeBLL = houseTypeBLL;
        }

        public HouseTypeBLL HouseTypeBLL { get; }








        /// <summary>
        /// 房型添加
        /// </summary>
        /// <param name="houseTypeModel"></param>
        /// <returns></returns>
        [HttpPost]
        public int HouseTypeAdd(HouseTypeModel houseTypeModel)
        {


            return HouseTypeBLL.HouseTypeAdd(houseTypeModel);
        }





        /// <summary>
        /// 图片上传 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpFiles(IFormFile file) 
        {
            var str = Guid.NewGuid();
            var path = Directory.GetCurrentDirectory() + @"\wwwroot\img" + str + file.FileName;
            using (FileStream fs= new FileStream(path,FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Close();
                return Ok("https://localhost:7059/img"+str+file.FileName);

            }
        
        
        }



        /// <summary>
        /// 房型显示
        /// </summary>
        /// <param name="count"></param>
        /// <param name="page"></param>
        /// <param name="HouseTypeName"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult HouseTypeList( string? HouseTypeName, int index = 1, int size = 2)
        {

            int count = 0; int page = 0;

            var  list= HouseTypeBLL.HouseTypeList(out count, out page, HouseTypeName, index, size);
            return Ok(new{ list= list, page= page, count = count });

        }




        /// <summary>
        /// 房型删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int HouseTypeDel(int id)
        {
            return HouseTypeBLL.HouseTypeDel(id);
        }





        ///-----------------------------------------------------------------------------------------------------

        /// <summary>
        /// 房号添加
        /// </summary>
        /// <param name="houseNoModel"></param>
        /// <returns></returns>
        [HttpPost]
        public int HouseNoAdd(HouseNoModel houseNoModel)
        {


            return HouseTypeBLL.HouseNoAdd(houseNoModel);

        }




        /// <summary>
        /// 房号显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public List<HouseNoModel> HouseNoList()
        {
            return HouseTypeBLL.HouseNoList();
        }




        /// <summary>
        ///房号反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public HouseNoModel HouseNoAll(int id)
        {
            return HouseTypeBLL.HouseNoAll(id);
        }





        /// <summary>
        /// 房号修改
        /// </summary>
        /// <param name="HouseNoModel"></param>
        /// <returns></returns>
        [HttpPut]
        public int HouseNoUpd(HouseNoModel HouseNoModel)
        {

            return HouseTypeBLL.HouseNoUpd(HouseNoModel);
        }





        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="State"></param>
        /// <returns></returns>
        [HttpPut]
        public int HouseNoState(string ids, int State)
        {


           return HouseTypeBLL.HouseNoState(ids, State);

        }





















    }
}
